package com.zib.bilibili.view;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.zib.bilibili.R;
import com.zib.bilibili.adapter.MyPagerAdapter;
import com.zib.bilibili.base.BaseActivity;
import com.zib.bilibili.utils.ImageLoader;
import com.zib.bilibili.view.fragment.GiftTopFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import tv.danmaku.ijk.media.widget.media.AndroidMediaController;
import tv.danmaku.ijk.media.widget.media.IjkVideoView;

public class LiveActivity extends BaseActivity {


    @Bind(R.id.ijkvideoview_live)
    IjkVideoView ijkvideoviewLive;
    @Bind(R.id.imageview_icon_liveactivity)
    ImageView imageviewIconLiveactivity;
    @Bind(R.id.textview_uname_liveactivity)
    TextView textviewUnameLiveactivity;
    @Bind(R.id.textview_level_liveactivity)
    TextView textviewLevelLiveactivity;
    @Bind(R.id.Textview_onlinenum_liveactivity)
    TextView TextviewOnlinenumLiveactivity;
    @Bind(R.id.textview_follewnum_liveactivity)
    TextView textviewFollewnumLiveactivity;
    @Bind(R.id.imageView_follow_liveactivity)
    ImageView imageViewFollowLiveactivity;
    @Bind(R.id.tablayout_live)
    TabLayout tablayoutLive;
    @Bind(R.id.viewpager_live)
    ViewPager viewpagerLive;
    @Bind(R.id.iv_gift_live)
    ImageView ivGiftLive;
    @Bind(R.id.et_cintent_live)
    EditText etCintentLive;
    @Bind(R.id.iv_send_live)
    ImageView ivSendLive;
    private Context context = this;

    @Override
    public int getLayoutId() {
        return R.layout.activity_live;
    }

    @Override
    public void initView() {
        initIjkplayer();
        ImageLoader.getInstance().displayImage(context,getIntent().getExtras().getString("iconurl"),imageviewIconLiveactivity);
        /*
        *
        *
        *
        * */
        initPagerView();
    }

    private void initPagerView() {
        List<Fragment> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Fragment f = GiftTopFragment.newInstance(getIntent().getExtras().getInt("roomid"));
            list.add(f);
        }
        viewpagerLive.setAdapter(new MyPagerAdapter(getSupportFragmentManager(),list,getResources().getStringArray(R.array.live_fragmenttab)));
        tablayoutLive.setupWithViewPager(viewpagerLive);
        viewpagerLive.setOffscreenPageLimit(2);
    }

    private void initIjkplayer() {
        IjkMediaPlayer.loadLibrariesOnce(null);
        IjkMediaPlayer.native_profileBegin("libijkplayer.so");
        AndroidMediaController controller = new AndroidMediaController(this, false);
        ijkvideoviewLive.setMediaController(controller);
        ijkvideoviewLive.setVideoURI(Uri.parse(getIntent().getExtras().getString("playurl")));
        ijkvideoviewLive.start();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
